#!/bin/sh

CWD=`pwd`
INSTALL_DIR="$CWD/../.."
LIB_DIR="$INSTALL_DIR/lib"
INCLUDE_DIR="$INSTALL_DIR/include"
EV_INCLUDE_DIR="$INCLUDE_DIR/ev"

/bin/sh autogen.sh

#env CFLAGS=-g ./configure --prefix=$INSTALL_DIR 
#make && make install && make distclean
#mv $LIB_DIR/libev.a $LIB_DIR/libev_d.a

if ! [ -e $LIB_DIR/libev.a ]
then
    ./configure --prefix=$INSTALL_DIR --enable-shared=no
    make && make install && make distclean
    if [ $? -ne 0 ]
    then
        exit $?
    fi

    mkdir -p $EV_INCLUDE_DIR
    for file in ev.h ev++.h event.h
    do
        sed -e 's!"ev.h"!"ev/ev.h"!' $INCLUDE_DIR/$file > $EV_INCLUDE_DIR/$file
        rm -f $INCLUDE_DIR/$file
    done
fi

exit 0
